<?php
// Tim'Roster
// Copyright (c) 2011 Nicolas Nallet <aspgic2@gmail.com>
//
// This file is part of Tim'Roster.
//
// Tim'Roster is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Tim'Roster is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA

$xml_config = simplexml_load_file('config.xml');

include_once($_SERVER["DOCUMENT_ROOT"].$xml_config->roster_root_directory.'/class/Item_Family.php');

function generate_table($room){
    if (count($room) > 0) {
        echo '<table border=2><tr>
                    <th>'.Language::get_instance()->get_label('lb_item').'</th>
                    <th>'.Language::get_instance()->get_label('lb_code').'</th>
                    <th>'.Language::get_instance()->get_label('lb_item_class').'</th>
                    <th>'.Language::get_instance()->get_label('lb_item_type').'</th>
                    <th>'.Language::get_instance()->get_label('lb_quantity').'</th>
             </tr>' ;

         //split stack > 999 items in stack of 999 items
        foreach ($room as $item){

            for ($i = 0; $i < floor($item->get_quantity()/999) ; $i++) {
                generate_table_line($item->get_code()
                        //generate icon url with the right quantity
                        ,str_replace('&s='.$item->get_quantity(), '&s=999', $item->get_icon()).'<br>'
                        ,$item->get_item_class_label(), $item->get_item_type_label(), 999);
            }

            generate_table_line($item->get_code()
                        //generate icon url with the right quantity
                        ,str_replace('&s='.$item->get_quantity(), '&s='.($item->get_quantity()%999), $item->get_icon()).'<br>'
                        ,$item->get_item_class_label(), $item->get_item_type_label(), $item->get_quantity()%999);

        }

        echo '</table>' ;
    }
}

function generate_table_line($code, $icon, $item_class, $item_type, $quantity){
    
    echo '<tr>';
    echo '<td><img src="'.$icon.'" /></td>';
    echo '<td>'.$code.'</td>';
    echo '<td>'.$item_class.'</td>';
    echo '<td>'.$item_type.'</td>';
    echo '<td>'.$quantity.'</td>';
    echo '</tr>';
}

function generate_table_line_transaction($code, $icon, $item_class, $item_type, $quantity, $trans_type, $trans_date){

    echo '<tr>';
    echo '<td><img src="'.$icon.'" /></td>';
    echo '<td>'.$code.'</td>';
    echo '<td>'.$item_class.'</td>';
    echo '<td>'.$item_type.'</td>';
    echo '<td>'.$quantity.'</td>';
    echo '<td>'.$trans_type.'</td>';
    echo '<td>'.$trans_date.'</td>';
    echo '</tr>';
}

function generate_item_type_family_and_code_dropdown(){
    $content = '<select name="type_dd" id="type_dd" class="large_dd" onchange="refreshDropDown(this.form, \'type_dd\', \'fam_dd\',\'type\' );">';

    $type_array = Item_Family_Type::get_family_type();



    for ($i = 0; $i < count($type_array); $i++) {
        $type = $type_array[$i];

        $content .= '<option id="dd_child" value="'.$type->get_id().'" title="'.$type->get_icon().'" >'.$type->get_label().'</option>';
    }


    $content .= '</select>';

    $fam_array = Item_Family::get_family(null);

    $content .=  '<select name="fam_dd" id="fam_dd" class="large_dd" onchange="refreshDropDown(this.form, \'fam_dd\',\'code_dd\',\'family\' );">';



    for ($i = 0; $i < count($fam_array); $i++) {
        $fam = $fam_array[$i];

        $content .= '<option value="'.$fam->get_id().'" title="'.$fam->get_icon().'" >'.$fam->get_label().'</option>';
    }

    $content .= '</select>';

    $content .= '<select name="code_dd" id="code_dd" class="large_dd">
                    <option value="">All Code</option></select>';

    return $content;
}

function generate_item_quality_dropdown(){
    return '<select id="qlt_dd" >
        <option value="" ></option>
        <option value="270" >270</option>
        <option value="260" >260</option>
        <option value="250" >250</option>
        <option value="240" >240</option>
        <option value="230" >230</option>
        <option value="220" >220</option>
        <option value="210" >210</option>
        <option value="200" >200</option>
        <option value="190" >190</option>
        <option value="180" >180</option>
        <option value="170" >170</option>
        <option value="160" >160</option>
        <option value="150" >150</option>
        <option value="140" >140</option>
        <option value="130" >130</option>
        <option value="120" >120</option>
        <option value="110" >110</option>
        <option value="100" >100</option>
        <option value="90" >90</option>
        <option value="80" >80</option>
        <option value="70" >70</option>
        <option value="60" >60</option>
        <option value="50" >50</option>
        <option value="40" >40</option>
        <option value="30" >30</option>
        <option value="20" >20</option>
        <option value="10" >10</option>
        <option value="0" >0</option>
        </select>';
}

function generate_comparaison_signe_dropdown($dropdown_name){
    return '<select id="'.$dropdown_name.'" >
        <option value="" ></option>
        <option value="=" >=</option>
        <option value=">" >></option>
        <option value="<" ><</option>
        <option value=">=" >>=</option>
        <option value="<=" ><=</option>
        </select>';
}


function generate_search_resume($type, $family, $code, $quality, $quality_com_signe){
    $content = '<h2 class="trigger"><a href="#">'.Language::get_instance()->get_label('lb_search_critera').'</a></h2>
                <div class="toggle_container">
                <div class="block">';


    if (isset($type)){
        $content .= Language::get_instance()->get_label('lb_item_family_type').' : <img src="'.Item_Family_Type::get_family_type_by_id($type)->get_icon().'" />'.Item_Family_Type::get_family_type_by_id($type)->get_label().'<br />';
    }

    if (isset($family)){
        $content .= Language::get_instance()->get_label('lb_item_family').' : <img src="'.Item_Family::get_family_by_id($family)->get_icon().'" />'.Item_Family::get_family_by_id($family)->get_label().'<br />';
    }

    if (isset($code)){
        $content .= Language::get_instance()->get_label('lb_item_code').' : '.Item_Code::get_item_code_by_id($code)->get_label().'<br/>';
    }

    if ((isset($quality)) && (isset($quality_com_signe))){
        $content .= Language::get_instance()->get_label('lb_quality').' : '.$quality_com_signe.' '.$quality;
    }

    $content .= '</div></div><br/>';

    return $content;
}

?>
